<template>
  <div class="app-container">
   <el-form :inline="true" ref="ruleForm" :rules="refRule" :model="formInline" class="demo-form-inline">
    <el-form-item label="时间" prop="time">
      <el-date-picker
      class="date-picker-box"
        v-model="formInline.time"
        type="datetimerange"
        align="right"
        unlink-panels
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        value-format="yyyy-MM-dd HH:mm:ss"
        :default-time="['00:00:00', '23:59:59']"
        :picker-options="pickerWeekStep" >
      </el-date-picker>
      </el-form-item>
      <el-form-item label="处理日期" prop="dealDate">
        <el-date-picker
          v-model="formInline.dealDate"
          align="center"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
       <el-form-item label="游戏平台" prop="gamePlatform">
        <el-select v-model="formInline.gamePlatform"   placeholder="请选择"  style="width:200px">
          <el-option
            v-for="item in GAME_PLATFORM_LIST.filter((item)=>{return item.type.includes('thirdRealTimeData')})"
            :label="item.title"
            :key="item.value"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
       <el-form-item label="查询类型" prop="type">
        <el-select v-model="formInline.type"   placeholder="请选择"  style="width:200px">
          <el-option
            v-for="item in SELECT_TYPE"
            :label="item.title"
            :key="item.value"
            :value="item.value"

          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button class="filter-item" type="primary" icon="el-icon-search" @click="toSearch" >搜索
        </el-button>
        <el-button @click="selfResetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>

</template>
<script>
import { form, factory, pickerOption } from '@/build';
import { GAME_PLATFORM_LIST, SELECT_TYPE } from './data';

export default {
  name: 'form-filter',
  mixins: [form, factory, pickerOption],
  data() {
    return {
      GAME_PLATFORM_LIST,
      SELECT_TYPE,
      formInline: {
        time: [
          moment().format('YYYY-MM-DD 00:00:00'),
          moment().format('YYYY-MM-DD 23:59:59'),
        ],
        gamePlatform: undefined,
        dealDate: moment().format('YYYY-MM-DD'),
        type: undefined,
        page: 1,
        size: 20,
      },
      refRule: {
        time: [
          { required: true, message: '时间为必选项', trigger: 'change' },
        ],
        type: [
          { required: true, message: '查询类型为必选项', trigger: 'change' },
        ],
        gamePlatform: [
          { required: true, message: '游戏平台为必选项', trigger: 'change' },
        ],
        dealDate: [
          { required: true, message: '处理日期为必填项', trigger: 'change' },
        ],

      },
    };
  },
  methods: {

    toSearch() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          const formInline = _.cloneDeep(this.formInline);
          formInline.dealDate += ' 00:00:00';
          this.$emit('on-filter', formInline);
        } else {
          return false;
        }
      });
    },
    selfResetForm(formName) {
      this.resetForm(formName);
      this.$emit('clear');
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          this.$emit('on-filter', this.formInline);
        } else {
          return false;
        }
      });
    },
  },

  mounted() {

  },
};
</script>

<style lang="scss" scoped>

</style>
